package cdu.sl.controller;

import cdu.sl.pojo.dto.StudentGeneralReviewPageQueryDTO;
import cdu.sl.pojo.dto.StudentScoreInfoDTO;
import cdu.sl.pojo.dto.SubmitScoreInfoDTO;
import cdu.sl.pojo.vo.StudentGeneralReviewVO;
import cdu.sl.pojo.vo.TestItemScoreInfoVO;
import cdu.sl.pojo.vo.TestItemVO;
import cdu.sl.result.PageResult;
import cdu.sl.result.Result;
import cdu.sl.service.DataReportService;
import cdu.sl.service.StudentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
@RequiredArgsConstructor
public class StudentController {

    private final StudentService studentService;

    private final DataReportService dataReportService;

    @GetMapping("/page")
    public Result getStudentGeneralReview(StudentGeneralReviewPageQueryDTO studentGeneralReviewPageQueryDTO) {
        log.info("分页条件查询学生数据：{}", studentGeneralReviewPageQueryDTO);
        PageResult<StudentGeneralReviewVO> pageResult = studentService.page(studentGeneralReviewPageQueryDTO);
        return Result.success(pageResult);
    }


    /**
     * 根据学生id获取体测条目
     *
     * @return 学生体测条目
     */
    @GetMapping("/items/{studentId}")
    public Result getItemListByGrade(@PathVariable Long studentId) {
        log.info("根据学生id获取体测条目：{}", studentId);
        List<TestItemVO> testItemVOS = dataReportService.getTestItemsByStudentId(studentId);
        return Result.success(testItemVOS);
    }


    /**
     * 提交成绩信息
     */
    @PostMapping("/score/{studentId}")
    public Result submitScoreInfo(@PathVariable Long studentId, @RequestBody SubmitScoreInfoDTO scoreInfoDTO) {
        log.info("录入学生：{} 成绩 , 成绩详情 ：{}", studentId, scoreInfoDTO);
        dataReportService.submitScoreInfo(studentId, scoreInfoDTO);
        return Result.success();
    }

    /**
     * 根据id获取学生得分信息
     * @param studentId 学生id
     * @return 学生分数详情
     */
    @GetMapping("/score/{studentId}")
    public Result getStudentScoreInfoById(@PathVariable Long studentId) {
        log.info("根据学生id获取体测数据详情：{}", studentId);
        List<TestItemScoreInfoVO> testItemScoreInfoVOS = dataReportService.getStudentScoreInfoById(studentId);
        return Result.success(testItemScoreInfoVOS);
    }


    /**
     * 修改学生体测成绩
     * @param studentId    学生id
     * @param studentScoreInfoDTO 得分信息
     */
    @PutMapping("/score/{studentId}")
    public Result updateStudentScoreInfo(@PathVariable Long studentId, @RequestBody StudentScoreInfoDTO studentScoreInfoDTO) {
        log.info("根据学生id:{}修改学生体测数据：{}", studentId, studentScoreInfoDTO);
        dataReportService.updateStudentScoreInfo(studentId, studentScoreInfoDTO);
        return Result.success();
    }





}
